﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.Models
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess
@using OBUCare.Core.Common 
@using OBUCare.Web.Models

@model PartsTransactionGridViewInfo


 @(Html.Telerik().Grid<View_Parts_Transfer>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select(Model.Action, Model.Controler, new { sql = Model.DefaultSql })
                    )
        .Columns(columns =>
        {
            columns.Bound(o => o.Owner).Width("9%").Title("源营业厅");
            columns.Bound(o => o.AgentName).Width("9%").Title("目的营业厅");
            columns.Bound(o => o.SUPPLIER_NAME).Width("9%");
            columns.Bound(o => o.PARTS_NAME).Width("9%");
            columns.Bound(o => o.SPEC_NAME).Width("9%");
            columns.Bound(o => o.RECORD_DATE).Format("{0:yyyy-MM-dd}").Width("8%");
            columns.Bound(o => o.PARTS_COUNT).Width("8%");
            columns.Bound(o => o.OPERATOR_NAME).Width("8%");
            columns.Command(commands =>
            {
                commands.Custom("Reversal").ButtonType(CommonStyleForUI.Grid_ButtuonType)
                    .Text("冲正").Action("ConfirmReversal", "Parts").Ajax(true).DataRouteValues(route => route.Add(o => o.ID).RouteKey("id"));
            }).Width("8%").Title("操作").Visible(Model.IsShowAction);          
        }).TableHtmlAttributes(new { @style = "width:100%" })
                .ClientEvents(events =>
                {
                    events.OnError("onError");
                    events.OnDataBinding("onDataBinding");
                    events.OnComplete("onComplete");
                    events.OnCommand("onCommand");
                })
                .Pageable(paging =>
                {
                    paging.Style(CommonStyleForUI.Grid_PageStyle)
                    .Position(CommonStyleForUI.Grid_PagePosition)
                    .PageTo(CommonStyleForUI.Grid_CurrentPage)
                    .PageSize(CommonStyleForUI.Grid_PageSize);
                })
            //.Resizable(resizing => resizing.Columns(true))
                .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
            //.Selectable()
        )

<script language="javascript" type="text/javascript"> 

    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }
       

    function onDataBinding(e) {
        
        var strSearchSql = $('#searchSql').val();
        //grid自带的查询事件时，将其取消，只保留手动执行的查询
        if (strSearchSql.StringIsNullOrEmpty())
            e.preventDefault();
        else {

            var grid = $('#Grid').data('tGrid')
            index = (grid.currentPage - 1) * grid.pageSize;
            e.data = {
                // the key ("category") specifies the variable name of the action method which will contain the specified value
                searchSql: $('#searchSql').val(),
                agentNO: $('#agentNO').val()
                //,menuNames: $('#menuNames').val()
            };
        }
    }


    function onCommand(e) {
        
        //当点击更新号段后
        if (e.name == "Reversal")
        {
            if (!confirm("您确定要冲正此条记录？"))
            {
                e.preventDefault();
            }
        }
    }
    
    

    //号段详情列表，请求结束后的事件
    function onComplete(e) {
        
        //当点击更新号段后
        if (e.name == "Reversal") {
            var result = e.response;
            if (result.success) {
                var grid = $(this).data("tGrid");
                grid.ajaxRequest();
                alert("冲正成功");
            }
            else
                alert("冲正失败:" + result.message);
        }
    }
</script>
